// JavaScript Document
function check(){
	var usr=document.getElementById("user").value;
	var pass=document.getElementById("pass").value;
	if(usr=="admin" && pass=="1234"){
		setCookie("user",usr,3);
		alert(getCookie("user"));
		setInterval(window.location.assign("admin/admin-home.html"),3000);        //co the dung window.open tham so _self
		}
	}
/*Local cookie using (not for Chorme)*/
function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : " ; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
	}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
/*Using HTML 5 local storage*/
function login(){
	if(sessionStorage.userName!=""){
		sessionStorage.clear();
	}
	var usr=document.getElementById("user").value;
	var pass=document.getElementById("pass").value;
	if(usr=="minh"&&pass=="1234"){
	alert("Login sucessful!");
	sessionStorage.userName=usr;
	sessionStorage.count = 0;
	window.location.assign("home.html");
	}else if(usr=="admin"){
		sessionStorage.userName="usr";
		window.location.assign("admin/admin-home.html");
	}else{
		document.getElementById("alert").innerHTML="User name and password doesn't match";
	}
}
function loginCheck(){
	if(sessionStorage.userName){
		if(sessionStorage.count==0){
		alert("Welcome "+sessionStorage.userName);
		}
		sessionStorage.count=1;
		document.getElementById("top-page").innerHTML="<p>Hi&#33"+"&#32 &#32 &#32"+sessionStorage.userName+"&#32 &#32 &#32"+"<a href="+'"'+"#"+'"'+"onClick="+'"'+"clearStorage()"+'"'+'>'+"Logout</a></p>";
	}	
}
function clearStorage(){
	sessionStorage.clear();
	alert("Logout successful !");
	location.reload();
	}